home *** CD-ROM | disk | FTP | other *** search
- set output error
- set display page 23
- set more 1
- #delimit ;
-
- di _n(5) in wh
- " ___ ____ ____ ____ ____ tm" _n
- " /__ / ____/ / ____/" _n
- "___/ / /___/ / /___/ Estimating ANOVA and ANOCOVA Models" _n
- "-------------------------------------------------------------------" _n(2) ;
-
- di in gr
- "This tutorial provides an overview of the Stata commands for estimating" _n
- "analysis-of-variance (ANOVA) and analysis-of-covariance (ANOCOVA) models." _n
- "The commands we discuss are:" _n(2)
- _col(20) in wh "oneway anova test" _n(2)
- in gr
- "We will use a data set that records the changes in systolic blood pressure" _n
- "for 58 patients. Each patient suffered from one of three diseases, and each"
- _n
- "was given one of four drugs." _n(6) ;
-
-
- #delimit cr
- mac def path
- capture run nullfile.tut
- if _rc {
- mac def path "\stata\"
- capture run %path`nullfile.tut
- if _rc {
- mac def path "/usr/stata/"
- capture run %path`nullfile.tut
- if _rc {
- #delimit ;
- di in red
- "I cannot find the other tutorial files. I have looked in the current" _n
- "directory and in \stata (DOS) or /usr/stata (Unix). Is Stata installed" _n
- "correctly?" _n(2)
- "In any case, I cannot run the tutorial." ;
- #delimit cr
- exit
- }
- }
- }
- macro define F5 "do %path`contents.tut;"
- macro define F6 "do %path`anova.tut;"
- #delimit ;
-
- di in wh ". use %path`systolic, clear" ;
- noisily use %path`systolic, clear ;
- set more 0 ; more ; set more 1 ;
- di _n in wh ". describe" ;
- noisily describe ;
- di _n ". list in 1/7" ;
- noisily list in 1/7 ;
- set more 0 ; more ; set more 1 ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "Stata's '"
- in wh "oneway"
- in gr "' command estimates one-way ANOVA models and has options for" _n
- "performing several multiple-comparison (means separation) tests. Below," _n
- "we'll estimate a one-way model with the change in blood pressure as the" _n
- "response variable and the drug given each patient as the control." _n(2)
- "The syntax for estimating a one-way model is" _n(2)
- _col(16) in wh "oneway" in gr " response control" _n(2)
- "where 'response' is the name of the response variable and 'control' is the" _n
- "name of the control variable." _n
- in wh _dup(79) "-" _n(11)
- ". oneway systolic drug" ;
- set more 0 ; more ; set more 1 ;
- noisily oneway systolic drug ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "The reported between-group variance suggests that changes in systolic blood" _n
- "pressure are significantly different among patients receiving different med-"
- _n
- "ications." _n(2)
- "Stata will also report the mean value of the response variable for each level"
- _n
- "of the control if we add the '" in wh "tabulate" in gr "' option:" _n
- in wh _dup(79) "-" _n(2)
- ". oneway systolic drug, tabulate" ;
- set more 0 ; more ; set more 1 ;
- noisily oneway systolic drug, tabulate ;
- di _n ; set more 0 ; more ; set more 1 ;
-
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "Stata will perform the Bonferroni, Scheffe, and Sidak multiple-comparison" _n
- "tests on one-way ANOVA models. The tests are requested by adding an option" _n
- "to the "
- in wh "oneway"
- in gr " command. For instance, if we wanted to estimate our model and" _n
- "add the Bonferroni test, we type:" _n
- in wh _dup(79) "-" _n(17)
- ". oneway systolic drug, bonferroni" ;
- set more 0 ; more ; set more 1 ;
- noisily oneway systolic drug, bonferroni ;
- set more 0 ; more ; set more 1 ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "Stata's "
- in wh "anova"
- in gr " command performs N-way ANOVA and ANOCOVA estimation. It" _n
- "will estimate one-way ANOVA, too, but "
- in wh "oneway" in gr " is faster." _n(2)
- in wh
- "anova"
- in gr " is like all of Stata's estimation commands; after typing '"
- in wh "anova" in gr "', you" _n
- "specify the response variable and the control variables. Control variables" _n
- "may be interacted using the standard '"
- in wh "*" in gr "' notation. For example:" _n ;
-
- di
- in wh _col(15) "anova y a" in gr _col(37) "estimates a one-way layout" _n
- in wh _col(15) "anova y a b" in gr _col(37) "estimates a two-way layout" _n
- in wh _col(15) "anova y a b a*b" in gr _col(37)
- "estimates a two-way factorial layout" _n(2)
- "You can write more complicated layouts, too. Let's use our blood pressure" _n
- "data to illustrate these features. First, we'll specify a two-way model with"
- _n
- "no interaction. We will use blood pressure as the response variable and drug"
- _n
- "and disease as the controls." _n
- in wh _dup(79) "-" _n(7)
- ". anova systolic drug disease" ;
- set more 0 ; more ; set more 1 ;
- noisily anova systolic drug disease ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "The sums of squares used in the test are partial sums of squares. If we" _n
- "wanted to estimate the model sequentially with disease first, we would type:"
- _n
- in wh _dup(79) "-" _n(2)
- ". anova systolic disease drug, sequential" ;
- set more 0 ; more ; set more 1 ;
- noisily anova systolic disease drug, sequential ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "Let's return to ANOVA models using partial sums of squares. If we want to" _n
- "include the interaction of drug and disease, we type:" _n
- in wh _dup(79) "-" _n(2)
- ". anova systolic drug disease drug*disease" ;
- set more 0 ; more ; set more 1 ;
- noisily anova systolic drug disease drug*disease ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "We could have typed '"
- in wh "disease*drug" in gr "' instead of '"
- in wh "drug*disease" in gr "' and, since we are"
- _n
- "using partial sums of squares, terms can be in any order." _n
- in wh _dup(79) "-" _n ;
- set more 0 ; more ; set more 1 ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "After estimating an ANOVA model, you can specify various tests. We just esti-"
- _n
- "mated a model of systolic on drug, disease, and drug*disease. The F-test" _n
- "on drug was 9.05. We can obtain exactly the same result, the direct effect of"
- _n
- "drug, by typing:" _n
- in wh _dup(79) "-" _n(2)
- ". test drug" ;
- noisily test drug ;
-
- di _n(4) in wh _dup(79) "-" _n in gr
- "We can test more complicated hypotheses as well. For instance, if we type" _n
- "'"
- in wh "test drug drug*disease"
- in gr "', we test the effect of drug nested within disease."
- _n
- in wh _dup(79) "-" _n(2)
- ". test drug drug*disease" ;
- set more 0 ; more ; set more 1 ;
- noisily test drug drug*disease ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "Unless you specify otherwise, Stata uses the residual mean square as the error"
- _n
- "term. You may, however, request F-tests using other effects as the error "
- "term." _n
- in wh _dup(79) "-" _n(2)
- ". test drug, error(drug*disease)" ;
- noisily test drug, error(drug*disease) ;
- set more 0 ; more ; set more 1 ;
-
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "You can obtain the underlying regression model as well as the ANOVA table." _n
- "Let's illustrate with a simple two-way layout:" _n
- in wh _dup(79) "-" _n(2)
- ". anova systolic drug disease" ;
- noisily anova systolic drug disease ;
-
- di _n in wh _dup(79) "-" _n in gr
- "We can now obtain the regression by typing '"
- in wh "regress" in gr "':" _n
- in wh _dup(79) "-" ;
- set more 0 ; more ; set more 1 ;
- di _n in wh ". regress" ;
- noisily regress ;
- set more 0 ; more ; set more 1 ;
-
- di _n(10) in wh _dup(79) "-" _n in gr
- "We have illustrated how the "
- in wh "test" in gr " command can be used to test effects. "
- in wh "test" _n in gr
- "can also be used to test hypotheses about the individual coefficients." _n(2)
- "For example, we'll test whether the coefficient on the second drug is sta-" _n
- "tistically different than that on the third drug:" _n
- in wh _dup(79) "-" _n(3)
- ". test _coef[ drug[2] ] = _coef[ drug[3] ]" ;
- noisily test _coef[ drug[2] ] = _coef[ drug[3] ] ;
- set more 0 ; more ; set more 1 ;
-
- di _n(4) in wh _dup(79) "-" _n
- "test" in gr
- " has the ability to perform algebra, so that you can specify tests the" _n
- "way you want. Here's a simple, but crazy test:" _n
- in wh _dup(79) "-" _n(3)
- ". test _coef[disease[2]] + 3*_coef[disease[3]] = 6 + _coef[disease[3]]" ;
- noisily test _coef[disease[2]] + 3*_coef[disease[3]] = 6 + _coef[disease[3]] ;
- set more 0 ; more ; set more 1 ;
-
- di _n(9) in wh _dup(79) "-" _n in gr
- "Stata even has the capability to show you the symbolic form of the estimable"
- _n
- "functions and the symbolic form for a particular test. We'll illustrate by" _n
- "returning to our two-way factorial model. We must reestimate, but to save"
- _n
- "space we'll precede the command by '"
- in wh "quietly" in gr "' so that the ANOVA table does not" _n
- "appear." _n ;
-
- di in gr
- "On the next screen, we show the symbolic form of the estimable functions by" _n
- "typing '" in wh "test, symbolic" in gr "'." _n(2)
- "On the screen after that, we show the symbolic form of the test of drug by" _n
- "typing '" in wh "test drug, symbolic" in gr "'" _n
- in wh _dup(79) "-" _n(6)
- ". quietly anova systolic drug disease drug*disease" ;
- anova systolic drug disease drug*disease, nooutput ;
- di _n in wh ". test, symbolic" ;
- set more 0 ; more ; set more 1 ;
- noisily test, symbolic ;
- set more 0 ; more ; set more 1 ;
- di in wh _n ". test drug, symbolic" ;
- noisily test drug, symbolic ;
- set more 0 ; more ; set more 1 ;
-
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "The "
- in wh "anova"
- in gr " command can also estimate analysis-of-covariance (ANOCOVA) models," _n
- "just tell Stata which variables are continuous." _n(2)
- "We have another variation on our blood pressure data that contains the age" _n
- "of the patient as well as the increase in systolic blood pressure, drug," _n
- "and disease:" _n
- in wh _dup(79) "-" _n(2)
- ". use %path`sysage, clear" ;
- noisily use %path`sysage, clear ;
- di _n in wh ". summarize age" ;
- noisily summarize age ;
-
- di _n in wh _dup(79) "-" _n in gr
- "Let's estimate systolic as a function of drug, disease, age, and disease" _n
- "interacted with age:" _n
- in wh _dup(79) "-" _n(2)
- ". anova systolic drug disease age disease*age, continuous(age)" ;
- set more 0 ; more ; set more 1 ;
- noisily anova systolic drug disease age disease*age, continuous(age) ;
- di _n ; set more 0 ; more ; set more 1 ;
-
- macro define F6 "do %path`probit.tut;" ;
-
- di _n(4) in white
- "Demonstration ends" _n
- "------------------" _n ;
-
- di in green
- "That concludes our short demonstration, but there's much more. We now return"
- _n
- "control to you. Some suggestions:" _n ;
-
- di in green
- "If you ..." _col(34) "Then we will show you ..." _n
- " Press " in white "F5" in green _col(38) "a table of tutorial contents" _n
- " Press " in white "F6" in green _col(38) "the next tutorial, "
- in white "probit.tut" _n ;
-
- run %path`tobuy.tut ;